##################################################################
# File : /lua/maui/radial.lua
# Description : Radial Control
# Author : GPG
##################################################################

local Control = import('control.lua').Control
local Group = import('group.lua').Group
local LazyVar = import('/lua/lazyvar.lua')

Radial = Class(Group) {

    __init = function(self, parent, itemWidth, itemHeight, name)
        Group.__init(self, parent, name or "Grid")
        self._itemWidth = itemWidth
        self._itemHeight = itemHeight
        self._items = {}
    end,
    
    OnInit = function(self)
        Control.OnInit(self)
    end,
    
    SetItem = function(self, control, index)
        control:SetParent(self)
        self._items[index] = control
    end,
    
    SetPosition = function(self, pos)
        local baseRadius = table.getsize(self._items) * 9
        local phi = (2*math.pi)/table.getsize(self._items) 
        
        for i, v in self._items do
            local index = tonumber(i)
            local control = v
            v.Height:Set(40)
            v.Width:Set(40)
            v.Left:Set(function() return (pos[1] - control.Width()/2) + (baseRadius*math.cos(index*phi+(math.pi/2))) end)
            v.Top:Set(function() return (pos[2] - control.Width()/2) + (baseRadius*math.sin(index*phi+(math.pi/2))) end)
        end

    end,
    
    SelectItem = function(self, control)
        for i, v in self._items do
            v:Hide()
        end
        
        control:Show()
    end,
    
    GetItemBySlot = function(self, slot)
        return self._items[slot]
    end,
}